package com.jiepos.mpos.biz.http.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.jiepos.mpos.biz.affix.service.AppAffixInfService;
import com.jiepos.mpos.biz.appInfM.service.FeedbackService;
import com.jiepos.mpos.biz.appInfM.service.HeadAdvService;
import com.jiepos.mpos.biz.appInfM.service.HistoryService;
import com.jiepos.mpos.biz.appInfM.service.MessageInfService;
import com.jiepos.mpos.biz.appInfM.service.OrganizationService;
import com.jiepos.mpos.biz.channel.service.LogClientKeyService;
import com.jiepos.mpos.biz.customer.service.AppCustomerInfoService;
import com.jiepos.mpos.biz.customer.service.CustomAccountChangeService;
import com.jiepos.mpos.biz.customer.service.CustomAccountService;
import com.jiepos.mpos.biz.customer.service.CustomBankcardInfoService;
import com.jiepos.mpos.biz.customer.service.CustomLoginidChangeService;
import com.jiepos.mpos.biz.operationlog.service.SmsCodeFlowService;
import com.jiepos.mpos.biz.service.service.InsServiceParamService;
import com.jiepos.mpos.biz.transaction.service.LogTransJYLSService;
import com.jiepos.mpos.biz.user.service.AppInsInfService;
import com.jiepos.mpos.biz.workflowtrace.AppWorkflowTraceService;
import com.jiepos.mpos.common.constant.DBConstant;
import com.jiepos.mpos.common.constant.ExceptionConstant;
import com.jiepos.mpos.common.constant.RspCodeConstant;
import com.jiepos.mpos.common.constant.SystemConstant;
import com.jiepos.mpos.common.dao.CardBinDao;
import com.jiepos.mpos.common.entity.App_Affix_InfEntity;
import com.jiepos.mpos.common.entity.App_Client_FeedBackEntity;
import com.jiepos.mpos.common.entity.App_Custom_BankcardEntity;
import com.jiepos.mpos.common.entity.App_Custom_InfEntity;
import com.jiepos.mpos.common.entity.App_Log_Client_KeyEntity;
import com.jiepos.mpos.common.entity.App_WorkFlow_TraceEntity;
import com.jiepos.mpos.common.entity.GpsEntity;
import com.jiepos.mpos.common.service.AbrBaseHttpService;
import com.jiepos.mpos.common.service.SystemService;
import com.jiepos.mpos.core.entity.MposResponse;
import com.jiepos.mpos.core.util.CollectionUtil;
import com.jiepos.mpos.core.util.DateUtil;
import com.jiepos.mpos.core.util.StringUtils;
import com.jiepos.mpos.core.util.Tool3DES;
import com.jiepos.mpos.inter.fourelement.FourElements;
import com.jiepos.mpos.inter.fourelement.service.IFourElementService;

@Service
public class HttpCustomService  extends AbrBaseHttpService {
    @Autowired
    private HttpCommonService httpCommonService;
    @Autowired
    private AppCustomerInfoService appCustomerInfoService;
    @Autowired
    private SmsCodeFlowService smsCodeFlowService;
    @Autowired
    private InsServiceParamService insServiceParamService;
    @Autowired
    private LogTransJYLSService logTransJYLSService;
    @Autowired
    private CustomBankcardInfoService customBankcardInfoService;
    @Autowired
    private CustomAccountService customAccountService;
    @Autowired
    private CustomAccountChangeService customAccountChangeService;
    @Autowired
    private MessageInfService messageInfService;
    @Autowired
    private IFourElementService iFourElementService;
    @Autowired
    private LogClientKeyService logClientKeyService;
    @Autowired
    private CardBinDao cardBinDao;
    @Autowired
    private CustomLoginidChangeService customLoginidChangeService;
    @Autowired
    private AppWorkflowTraceService appWorkflowTraceService;
    @Autowired
    private FeedbackService feedbackService;
    @Autowired
    private AppAffixInfService appAffixInfService;
    @Autowired
    private AppInsInfService appInsInfService;
    @Autowired
    private OrganizationService organizationService;
    @Autowired
    private HeadAdvService headAdvService;
    @Autowired
    private SystemService systemService;
    @Autowired
    private HistoryService historyService;
    
    /**APP注册
     * @param request
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map queryCustomParam(HttpServletRequest request, String sign, GpsEntity gpsEntity,
                                String login_id, String pass_word, String rand, String super_login_id,
                                App_Custom_InfEntity appCustomInfEntity, String pay_pass_word) throws Exception {
        String serviceData = gpsEntity.getSerial_number() + StringUtils.objToString(login_id) + StringUtils.objToString(pass_word)
                + StringUtils.objToString(rand) + StringUtils.objToString(super_login_id) + StringUtils.objToString(pay_pass_word);
        Map checkSignMap = httpCommonService.checkCommonSign(request, serviceData, sign, "会员注册接口");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
        	boolean tempRand = smsCodeFlowService.checkRand(SystemConstant.RAND_SERVICE_TYPE_1,login_id,rand);
        	subLog.debug("本地验证码:{}", tempRand);
            //校验登陆账号是否存在
        	App_Custom_InfEntity customer = appCustomerInfoService.getCustomInfByLoginId(login_id);
            if (customer != null) {
                return this.getRspMap(RspCodeConstant.RSPCODE_200013, null, null);
            }
            //判断验证码是否重复
            /*if(!rand.equals(tempRand)){
               return this.getRspMap(RspCodeConstant.RSPCODE_200006,null,null);
            }*/
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity supCustomer = appCustomerInfoService.getCustomInfByLoginId(super_login_id);
            //未查到对应用户信息
            if (supCustomer == null) {
                subLog.info("推荐人账号不存在");
                return super.getRspMap(RspCodeConstant.RSPCODE_200028, null, null);
            }
            //推荐人是否认证
            if(!SystemConstant.AUTH_ST_1.equals(supCustomer.getRealname_auth_st())){
                return super.getRspMap(RspCodeConstant.RSPCODE_200027, null, null);
            }
            if(!tempRand){
                return this.getRspMap(RspCodeConstant.RSPCODE_200006,null,null);
            }else {
                smsCodeFlowService.updRand(SystemConstant.RAND_SERVICE_TYPE_1,login_id,rand);
            }
            //注册
            String cuntomRspCode = appCustomerInfoService.addAppCustomer(login_id, pass_word, pay_pass_word, supCustomer.getCustom_uuid(), supCustomer.getIns_uuid());
            Map dataMap = new HashMap();
            dataMap.put("cur_date", DateUtil.getCurrDateTimeStr());
            dataMap.put("cuntomRspCode", cuntomRspCode);
            return httpCommonService.getRspMap(SystemConstant.RSPCODE_SUCCESS, SystemConstant.RSPCODE_SUCCESS_MSG, dataMap);
        } else {
            return checkSignMap;
        }
    }

    /**
     * 查询登录参数
     *
     * @param request
     * @param login_id
     * @param pass_word
     * @param random_number
     * @param getui_clientid
     * @param gpsEntity
     * @return
     */
    public Map queryLoginParam(HttpServletRequest request, String login_id, String pass_word, String random_number,
                               String getui_clientid, String sign, GpsEntity gpsEntity) {
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(login_id) + StringUtils.objToString(pass_word);
        Map checkSignMap = httpCommonService.checkCommonSign(request, serviceData, sign, "会员登录");
        subLog.info("登录接口调用");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            Map dataMap = new HashMap();
            //版本判断
            //获取机构App设置信息
            Map<String, Object> insAppInfo = null;
            if(gpsEntity != null){ //app接口调用
                insAppInfo = organizationService.getInsAppInfoByAppid(gpsEntity.getAppType(), gpsEntity.getApp_id());
                if(insAppInfo != null){
                    String version = "";
                    if(SystemConstant.APP_TYPE_ANDROID.equals(gpsEntity.getAppType())){
                        version = StringUtils.objToString(insAppInfo.get("ANDROID_VERSION"));
                    } else if(SystemConstant.APP_TYPE_IOS.equals(gpsEntity.getAppType())) {
                        version = StringUtils.objToString(insAppInfo.get("IOS_VERSION"));
                    }
                    //客户端 低于 服务器版本
                    if(!"".equals(version) && gpsEntity.getVersion().compareTo(version) < 0){
                        dataMap = organizationService.getInsAppMap(gpsEntity);//organizationService.checkVersion(gpsEntity);
                        return super.getRspMap(SystemConstant.RSPCODE_UPDATE, "发现新版本", dataMap);
                    }

                }
            }
            if(insAppInfo == null){
                //App有误
                return this.getRspMap(RspCodeConstant.RSPCODE_200009, null, null);
            }
            //trace_no 交易流水号
            String sndTraceNO = logTransJYLSService.getSndTraceNO(login_id);
            dataMap.put("trace_no", sndTraceNO);
            //login_id 登录账号
            dataMap.put("login_id", login_id);
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomInfByLoginId(login_id);
            //未查到对应用户信息
            if (customInf == null) {
                subLog.info("登录账号无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            // OEM 验证登录账号
            if(!StringUtils.compare(StringUtils.objToString(insAppInfo.get("INS_UUID")),customInf.getIns_uuid())){
                subLog.info("OEM : 该登录账号不存在");
                return super.getRspMap(RspCodeConstant.RSPCODE_200012, "登录账号不存在", null);
            }
            //user_st 用户状态
            //判断用户状态，正常状态方可登录成功
            if (!SystemConstant.USER_ENABLED.equals(customInf.getUser_st())) {
                super.subLog.info("用户状态异常（用户已停用或已冻结）");
                return super.getRspMap(RspCodeConstant.RSPCODE_200103, null, null);
            }
            dataMap.put("user_st", customInf.getUser_st());
            //登录密码校验
            String newPassWord = null;
            try {
                newPassWord = appCustomerInfoService.getNewPassWord(pass_word, login_id, customInf.getCustom_no());
            } catch (Exception e) {
                e.printStackTrace();
                super.subLog.error("RSA解密异常");
                return super.getRspMap(RspCodeConstant.RSPCODE_200102, null, null);
            }
            //数据库中的密码
            String db_password = customInf.getPass_word();
            if (StringUtils.isEmpty(newPassWord) || StringUtils.isEmpty(db_password)
                    || !StringUtils.compare(newPassWord, db_password)) {
                super.subLog.info("忘记密码错误");
                //累加错误次数
                int count = 0;
                if (!StringUtils.isBlank(customInf.getCheck_login_count())) {
                    count = Integer.parseInt(customInf.getCheck_login_count());
                }
                //加一次
                count += 1;
                appCustomerInfoService.updateLoginCount(customInf.getCustom_uuid(), String.valueOf(count));
                // 判断登录错误次数 达到5次即冻结此用户
                if (count >= SystemConstant.LOGIN_ERROR_COUNT) {
                    Map<String, String> map = new HashMap<>();
                    map.put(SystemConstant.SESSION_LOGIN_USER, login_id);
                    appCustomerInfoService.updateUserSt(customInf.getCustom_uuid(), map, SystemConstant.USER_LOCKED);
                    super.subLog.info("密码错误已达[{}]次，用户【{}】已冻结", SystemConstant.LOGIN_ERROR_COUNT, login_id);
                }
                StringBuffer message = new StringBuffer();
                if(SystemConstant.LOGIN_ERROR_COUNT - count == 0){
                    //没有机会了
                    message.append("密码输入错误次数太多，用户已冻结");
                }else{
                    message.append("密码错误!还剩");
                    message.append(SystemConstant.LOGIN_ERROR_COUNT - count);
                    message.append("次机会");
                }
                return super.getRspMap(RspCodeConstant.RSPCODE_200011, message.toString(), null);
            }
            //重置错误次数
            appCustomerInfoService.updateLoginCount(customInf.getCustom_uuid(), "0");
            //check_login_count 校验登陆错误次数
            dataMap.put("check_login_count", "0");
            //custom_no 会员编号
            dataMap.put("custom_no", customInf.getCustom_no());
            //name 会员姓名
            dataMap.put("name", StringUtils.objToString(customInf.getName()));
            //certificate_no 身份证号
            dataMap.put("certificate_no",super.hideData("1",StringUtils.objToString(customInf.getCertificate_no())));
            //realname_auth_st 客户实名认证状态
            dataMap.put("realname_auth_st", customInf.getRealname_auth_st());
            //realname_audit_st 实名认证审核状态
            dataMap.put("realname_audit_st",customInf.getRealname_audit_st());
            //vip_st VIP认证状态
            dataMap.put("vip_st", customInf.getVip_st());
            //设置账户数据
            this.setAccountAmountData(dataMap,customInf);
            //设置消息通知数据
            this.setNoticeData(dataMap,customInf);
            //查询业务及业务参数数据
            this.setServiceData(dataMap,customInf);
            //credit_apply_url	String	信用卡申请地址
            List<Map<String, String>> codeListByTp = systemService.getCodeListByTp(SystemConstant.APPLY_CODE_TP);
            if(codeListByTp != null && codeListByTp.size()>0){
                for(Map<String, String> map : codeListByTp){
                    if(SystemConstant.APPLY_CODE_VAL.equals(StringUtils.objToString(map.get("code_val")))){
                        dataMap.put("credit_apply_url",StringUtils.objToString(map.get("code_desc")));
                    }
                }
            }
            //未找到 则设置为 ""
            if(dataMap.get("credit_apply_url") == null){
                dataMap.put("credit_apply_url","");
            }
            //token 生成token 加密保存入库
            String token = DateUtil.getCurrDateTimeStr() + super.createRandom(true, 4);
            subLog.debug("用户登录：生成token：" + token);
            //加密token入库
            //先得到数据明文
            String keyData = StringUtils.MD5(DateUtil.getCurrDateStr() + gpsEntity.getVersion());
            subLog.debug("用户登录：生成keyData：" + keyData);
            //本地加密秘钥对数据明文加密得到加密秘钥
            String key1 = Tool3DES.trides_crypt(SystemConstant.LOC_KEY, keyData);
            subLog.debug("用户登录：生成key1：" + key1);
            //用加密秘钥对密客户端随机数进行加密，得到token的加密秘钥
            String cryptStr = Tool3DES.trides_crypt(key1, random_number);
            subLog.debug("用户登录：生成cryptStr：" + cryptStr);
            //对登录时获取的token进行加密得到最终的签名秘钥
            String decrypt_key = Tool3DES.trides_crypt(cryptStr, token).toUpperCase();
            subLog.debug("用户登录：生成decrypt_key：" + decrypt_key);
            App_Log_Client_KeyEntity entity = new App_Log_Client_KeyEntity();
            entity.setRandom_number(cryptStr.toUpperCase());
            entity.setCustom_no(customInf.getCustom_no());
            entity.setClient_version(gpsEntity.getVersion());
            entity.setToken_key(decrypt_key);
            entity.setSession_id(request.getSession().getId());
            //app类型转编码存储
            entity.setApptype(this.changeAppTypeToCode(gpsEntity.getAppType()));
            entity.setApp_id(gpsEntity.getApp_id());
            entity.setLatitude(gpsEntity.getLatitude());
            entity.setLongitude(gpsEntity.getLongitude());
            entity.setCountry(gpsEntity.getCountry());
            entity.setProvince(gpsEntity.getProvince());
            entity.setLocality(gpsEntity.getLocality());
            entity.setSublocality(gpsEntity.getSublocality());
            entity.setThoroughfare(gpsEntity.getThoroughfare());
            entity.setSubthoroughfare(gpsEntity.getSubthoroughfare());
            entity.setLocaladdress(gpsEntity.getLocaladdress());
            entity.setSystem_name(gpsEntity.getSystem_name());
            entity.setSystem_uuid(gpsEntity.getSystem_uuid());
            entity.setSystem_version(gpsEntity.getSystem_version());
            entity.setSystem_device_model(gpsEntity.getSystem_device_model());
            Map<String, String> map = new HashMap<>();
            map.put(SystemConstant.SESSION_LOGIN_USER, login_id);
            logClientKeyService.saveLogClientKey(entity, map);
            dataMap.put("token", decrypt_key);
            //修改极光客户端id
            appCustomerInfoService.updateGetUIClientID(customInf.getCustom_uuid(), entity.getApptype(), getui_clientid);
            // 加载首页广告
            List headAdvList = headAdvService.getHeadAdvList(gpsEntity, SystemConstant.ADV_PLACE_4);
            dataMap.put("headAdvList",headAdvList);
            subLog.info("数据已加载完成，登录接口返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, dataMap);
        } else {
            return checkSignMap;
        }
    }

    //app类型转编码
    private String changeAppTypeToCode(String appType){
        if(SystemConstant.APP_TYPE_ANDROID.equals(appType)){
            return "1";
        }else if(SystemConstant.APP_TYPE_IOS.equals(appType)){
            return "2";
        }else{
            return appType;
        }
    }

    //账户数据（金额，分润，变动等）
    private void setAccountAmountData(Map dataMap,App_Custom_InfEntity customInf){
        //balance 当前账户余额 会员账户表 推荐佣金+充值佣金+分润
        String balance = customAccountService.getCustomAccountBalance(customInf.getCustom_uuid());
        dataMap.put("balance", balance);
        //recommend_users 当前推荐用户数 会员信息表 推荐人 两级
        String recommend_users = appCustomerInfoService.getRecommCount(customInf.getCustom_uuid());
        dataMap.put("recommend_users", recommend_users);
        //cur_trans_amt 当日交易金额 交易流水表 repcode="00" sum
        String cur_trans_amt = logTransJYLSService.getTransATByCustomNo(customInf.getCustom_no());
        dataMap.put("cur_trans_amt", cur_trans_amt);
        //all_trans_amt 累计交易金额
        String all_trans_amt = logTransJYLSService.getSumTransATByCustomNo(customInf.getCustom_no());
        dataMap.put("all_trans_amt",all_trans_amt);
        //cur_orders 当日订单数 交易流水表 repcode="00" App已不再展示
        dataMap.put("cur_orders", "0");
        //查询累计佣金及分润
        Map<String, String> sumCommissionAndProfit = customAccountChangeService.getSumCommissionAndProfit(customInf.getCustom_uuid());
        //all_profit 累计分润
        dataMap.put("all_profit",sumCommissionAndProfit.get("PROFIT"));
        //all_commission 累计佣金
        dataMap.put("all_commission",sumCommissionAndProfit.get("COMMISSION"));
        //查询当日佣金及分润
        Map<String, String> commissionAndProfit = customAccountChangeService.getCommissionAndProfit(customInf.getCustom_uuid(), DateUtil.getCurrDateStr());
        //cur_profit 当日分润  账户变动明细 serviceNo 为 分润业务  累加变动金额
        dataMap.put("cur_profit", commissionAndProfit.get("PROFIT"));
        //cur_commission 当日佣金 账户变动明细 serviceNo 为 佣金业务  累加变动金额
        dataMap.put("cur_commission", commissionAndProfit.get("COMMISSION"));
        //昨日的分润及佣金App已不再展示；
        //pre_profit 昨日分润 账户变动明细 serviceNo 为 分润业务  累加变动金额
        dataMap.put("pre_profit", "0.00");
        //pre_commission 昨日佣金 账户变动明细 serviceNo 为 佣金业务  累加变动金额
        dataMap.put("pre_commission", "0.00");
    }

    //消息通知数据
    private void setNoticeData(Map dataMap,App_Custom_InfEntity customInf){
        //noticeSize 未读通知公告总数
        String noticeSize = messageInfService.getUnReadNoticeCount(customInf.getIns_uuid(),customInf.getCustom_uuid(),customInf.getRec_crt_ts());
        dataMap.put("noticeSize", noticeSize);
        //notice_list List<Map> 通知公告集合
        List<Map<String, Object>> notice_list = messageInfService.getNoticeList(customInf.getIns_uuid(),customInf.getCustom_uuid(),customInf.getRec_crt_ts());
        dataMap.put("notice_list", notice_list);
    }

    //业务及业务参数数据
    private void setServiceData(Map dataMap,App_Custom_InfEntity customInf){
        //service_list List<Map> 已开通的业务集合
        //会员认证状态分析
        String customLevel = "";
        if (SystemConstant.AUTH_ST_1.equals(customInf.getVip_st())) {
            //Vip认证
            customLevel = SystemConstant.CUSTOM_LEVEL_2;
        } else if (SystemConstant.AUTH_ST_1.equals(customInf.getRealname_auth_st())) {
            //实名认证
            customLevel = SystemConstant.CUSTOM_LEVEL_1;
        }else{
            //未认证的 暂时返回实名认证级别的数据给app
            customLevel = SystemConstant.CUSTOM_LEVEL_1;
        }
        List<Map<String, Object>> service_list = insServiceParamService.getInsParamListByInsUUIDAndCustomLevel(customInf.getIns_uuid(), customLevel);
        dataMap.put("service_list", service_list);
    }

    /**
     * 查询用户基本信息
     *
     * @param request
     * @param login_id
     * @param custom_no
     * @param random_number
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map queryCustomInfo(HttpServletRequest request, String login_id, String custom_no, String random_number, String sign, GpsEntity gpsEntity) {
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(login_id);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/getCustomInfo.do", gpsEntity, "获取用户基本信息");
        subLog.info("获取用户基本信息接口调用");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            Map dataMap = new HashMap();
            //login_id 登录账号
            dataMap.put("login_id", login_id);
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //user_st 用户状态
            dataMap.put("user_st", customInf.getUser_st());
            //check_login_count 校验登陆错误次数
            dataMap.put("check_login_count", customInf.getCheck_login_count());
            //custom_no 会员编号
            dataMap.put("custom_no", customInf.getCustom_no());
            //name 会员姓名
            dataMap.put("name", StringUtils.objToString(customInf.getName()));
            //certificate_no 身份证号
            dataMap.put("certificate_no",super.hideData("1",StringUtils.objToString(customInf.getCertificate_no())));
            //realname_auth_st 客户实名认证状态
            dataMap.put("realname_auth_st", customInf.getRealname_auth_st());
            //realname_audit_st 实名认证审核状态
            dataMap.put("realname_audit_st",customInf.getRealname_audit_st());
            //vip_st VIP认证状态
            dataMap.put("vip_st", customInf.getVip_st());
            //设置账户数据
            this.setAccountAmountData(dataMap,customInf);
            //设置消息通知数据
            this.setNoticeData(dataMap,customInf);
            //查询业务及业务参数数据
            this.setServiceData(dataMap,customInf);
            subLog.info("数据已加载完成，获取用户基本信息接口返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, dataMap);
        } else {
            return checkSignMap;
        }
    }

    /**
     * 获取会员基本信息
     * @param request
     * @param login_id
     * @param custom_no
     * @param random_number
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map getCustomPersonInfo(HttpServletRequest request, String login_id, String custom_no, String random_number, String sign, GpsEntity gpsEntity){
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number())+StringUtils.objToString(custom_no);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number, gpsEntity.getVersion(),
                serviceData, login_id, "httpcommon/getCustomPersonInfo.do", gpsEntity, "获取会员基本信息");
        subLog.info("获取会员基本信息接口调用");
        if(checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)){
            //参数非空校验
            if (StringUtils.isBlank(custom_no)) {
                subLog.info("参数为空");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            //根据会员编号得到登录会员信息
            Map dataMap = appCustomerInfoService.getCustomerInfoByCustomNo(custom_no);
            subLog.info("获取会员基本信息完成，接口已返回");
            return this.getRspMap(SystemConstant.RSPCODE_SUCCESS, SystemConstant.RSPCODE_SUCCESS_MSG, dataMap);
        }
        return checkSignMap;
    }


    /**
     * 用户账号重复性验证
     *
     * @param request
     * @param gpsEntity
     * @param login_id
     * @return
     */
    public Map checkLoginId(HttpServletRequest request, String login_id, String sign, GpsEntity gpsEntity) {

        String serviceData = gpsEntity.getSerial_number() + StringUtils.objToString(login_id);
        Map checkSignMap = this.checkCommonSign(request, serviceData, sign, "用户账号重复校验接口");
        //验签
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
        	App_Custom_InfEntity customer = appCustomerInfoService.getCustomInfByLoginId(login_id);
            //验证手机号是否存在
            if (customer == null) {
                return this.getRspMap(RspCodeConstant.RSPCODE_200012, null, null);
            }
        }
        return checkSignMap;
    }

    /**
     * 获取我的银行卡信息
     *
     * @param request
     * @param login_id
     * @param random_number
     * @param sign
     * @param custom_no
     * @param gpsEntity
     * @return
     * @throws Exception
     */
    public Map getMyBankCard(HttpServletRequest request, String login_id, String random_number, String sign, String custom_no, GpsEntity gpsEntity) throws Exception {

        String serviceData = gpsEntity.getSerial_number() + StringUtils.objToString(login_id) + StringUtils.objToString(custom_no);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/getMyBankCard.do", gpsEntity, "获取银行卡接口");
        App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
        //未查到对应用户信息
        if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
            subLog.info("登录账户无效");
            return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
        }
        //验签
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            Map dataMap = new HashMap();

           /* //获取银行卡的uuid
            String bankUuid = customBankcardInfoService.getBankUuid(customInf.getCustom_uuid());
            //获取审核意见
            String audit_desc = appWorkflowTraceService.getAuditCommentsBySystemkey(bankUuid);
            dataMap.put("audit_desc",audit_desc);*/
            List bank_card_list = customBankcardInfoService.getMyBankCard(login_id, random_number, sign, custom_no, gpsEntity);
            if (CollectionUtil.isEmpty(bank_card_list)) {
                dataMap.put("bank_card_list", new ArrayList<>());
                return this.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, dataMap);
            }

            dataMap.put("bank_card_list", bank_card_list);
            subLog.debug("获取银行卡基本信息:{}", dataMap);
            return this.getRspMap(SystemConstant.RSPCODE_SUCCESS, SystemConstant.RSPCODE_SUCCESS_MSG, dataMap);
        }
        return checkSignMap;
    }

    /**
     * 新增信用卡
     *
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param credit_card_no
     * @param credit_phone
     * @param cvv2
     * @param crd_exp
     * @param gpsEntity
     * @return
     */
    public Map saveCreditCard(HttpServletRequest request, String login_id, String random_number,
                              String custom_no, String credit_card_no, String credit_phone,
                              String cvv2, String crd_exp, String sign, GpsEntity gpsEntity) throws Exception {
       String serviceData = gpsEntity.getSerial_number()+StringUtils.objToString(custom_no)+StringUtils.objToString(credit_card_no)+StringUtils.objToString(credit_phone);
        Map checkSignMap = this.getLogClientKeyEntity(request,gpsEntity.getSerial_number(),sign,random_number,
                gpsEntity.getVersion(),serviceData,login_id,"httpcustom/saveCreditCard.do",gpsEntity,"新增信用卡接口");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {

            //判断是否存在总行行号和总行名称
            Map CardBinInf = customBankcardInfoService.getCardBinInf(credit_card_no);
            String super_bank_no = String.valueOf(CardBinInf.get("super_bank_no"));
            if(StringUtils.isEmpty(super_bank_no)){
                return super.getRspMap(RspCodeConstant.RSPCODE_200016, null, null);
            }
            //判断判断是否存在总行名称
            String super_bank_nm = String.valueOf(CardBinInf.get("super_bank_nm"));
            if(StringUtils.isEmpty(super_bank_nm)){
                return super.getRspMap(RspCodeConstant.RSPCODE_200025, null, null);
            }
            //判断卡性质
            String acct_attr = String.valueOf(CardBinInf.get("acct_attr"));
            //判断是否为贷记卡
            if (!acct_attr.equals(SystemConstant.CRD_NATURE_2)) {
                return super.getRspMap(RspCodeConstant.RSPCODE_200018, null, null);
            }
            //判断是否存在信用卡
            String is_credit_card_no = customBankcardInfoService.getCredit_card_no(credit_card_no);
            if (!StringUtils.isEmpty(is_credit_card_no)) {
                return super.getRspMap(RspCodeConstant.RSPCODE_200019, null, null);
            }
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //四要素认证
            Map<String, String> map = new HashMap<>();
            map.put(SystemConstant.SESSION_LOGIN_USER, login_id);
            Map resultMap = iFourElementService.queryFourElement(new FourElements(customInf.getIns_uuid(), customInf.getName(),credit_phone,customInf.getCertificate_no(), credit_card_no), map);
            if (resultMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
	            //保存信用卡
	            String CreditCard = customBankcardInfoService.saveCreditCard(request, login_id, custom_no, credit_card_no, credit_phone, cvv2, crd_exp);
	            Map dataMap = new HashMap();
	            dataMap.put("CreditCard", CreditCard);
	            return this.getRspMap(SystemConstant.RSPCODE_SUCCESS, SystemConstant.RSPCODE_SUCCESS_MSG, dataMap);
            } else{
                //返回四要素失败认证信息
                subLog.info("四要素认证失败");
                return getRspMap(RspCodeConstant.RSPCODE_300028, StringUtils.objToString(resultMap.get(SystemConstant.RSP_MSG)), null);
            }
        }
        return checkSignMap;
    }


    /**
     * 实名认证接口
     *
     * @param request
     * @param response
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param certificate_no
     * @param name
     * @param super_bank_no
     * @param super_bank_nm
     * @param bank_province
     * @param bank_locality
     * @param settle_bank_no
     * @param bank_nm
     * @param settle_acct
     * @param acct_nm
     * @param credit_card_no
     * @param credit_phone
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map saveRealNameAuth(HttpServletRequest request, HttpServletResponse response,
                                String login_id, String random_number, String custom_no,
                                String certificate_no, String name, String super_bank_no, String super_bank_nm,
                                String bank_province, String bank_locality, String settle_bank_no, String bank_nm,
                                String settle_acct,String settle_phone, String acct_nm, String credit_card_no, String credit_phone,String cvv2,String crd_exp,
                                String sign, GpsEntity gpsEntity) {
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(custom_no)
                + StringUtils.objToString(certificate_no) + StringUtils.objToString(name) + StringUtils.objToString(super_bank_no) + StringUtils.objToString(super_bank_nm)
                + StringUtils.objToString(bank_province) + StringUtils.objToString(bank_locality) + StringUtils.objToString(settle_bank_no) + StringUtils.objToString(bank_nm)
                + StringUtils.objToString(settle_acct) + StringUtils.objToString(acct_nm) + StringUtils.objToString(credit_card_no) + StringUtils.objToString(credit_phone);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/saveRealNameAuth.do", gpsEntity, "实名认证");
        subLog.info("实名认证接口调用");
        //验签
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //看该会员是否已经实名认证过
            if(SystemConstant.AUTH_ST_1.equals(customInf.getRealname_auth_st())){
                subLog.info("重复实名认证");
                return super.getRspMap(RspCodeConstant.RSPCODE_200109, null, null);
            }
            //参数非空校验
            if (StringUtils.isBlank(name) || StringUtils.isBlank(settle_phone) || StringUtils.isBlank(credit_phone) || StringUtils.isBlank(certificate_no) || StringUtils.isBlank(credit_card_no)
                    || StringUtils.isBlank(super_bank_no) || StringUtils.isBlank(super_bank_nm) || StringUtils.isBlank(bank_province) || StringUtils.isBlank(bank_locality)
                    || StringUtils.isBlank(settle_bank_no) || StringUtils.isBlank(bank_nm) || StringUtils.isBlank(settle_acct) || StringUtils.isBlank(acct_nm)
                    || StringUtils.isBlank(cvv2) || StringUtils.isBlank(crd_exp)) {
                subLog.info("参数为空");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            //身份证重复性校验
            App_Custom_InfEntity customInfByCertificateNo = appCustomerInfoService.getCustomInfByCertificateNo(certificate_no);
            if(customInfByCertificateNo != null){
                subLog.info("该身份证号已实名认证");
                return super.getRspMap(RspCodeConstant.RSPCODE_200113, null, null);
            }
            //卡bin校验 验证卡号是否是信用卡及借记卡
            Map<String, String> creditCardBinInf = cardBinDao.getCardBinAttr(credit_card_no);
            String crd_nature = creditCardBinInf.get("crd_nature");
            if (!SystemConstant.CRD_NATURE_2.equals(crd_nature)) {
                subLog.info("不是有效的信用卡");
                return super.getRspMap(RspCodeConstant.RSPCODE_200106, null, null);
            }
            Map<String, String> settleCardBinInf = cardBinDao.getCardBinAttr(settle_acct);
            String setcrd_nature = settleCardBinInf.get("crd_nature");
            if (!SystemConstant.CRD_NATURE_1.equals(setcrd_nature)) {
                subLog.info("不是有效的借记卡");
                return super.getRspMap(RspCodeConstant.RSPCODE_200107, null, null);
            }
            //银行卡校验是否是银联标准卡
            Boolean checkNumber = this.checkNumber(settle_acct);
            if(!checkNumber){
                return super.getRspMap(RspCodeConstant.RSPCODE_200115, null, null);
            }
            //----------重复性校验-----------
            //管理系统审核点通过的时候也会做重复性校验，如果卡号+身份证号有审核通过的，那么第二个相同信息只能退回修改
            //先看该信用卡号是否已绑定过；
            boolean saved = customBankcardInfoService.alreadySaveCardInfo(customInf.getCustom_uuid(), credit_card_no);
            //已有保存的，说明该卡认证过；
            if (saved) {
                subLog.info("该身份证号+信用卡号已经实名认证过");
                return super.getRspMap(RspCodeConstant.RSPCODE_200104, null, null);
            }
            //再看清算账户是否已经绑定过
            saved = customBankcardInfoService.alreadySaveCardInfo(customInf.getCustom_uuid(), settle_acct);
            if (saved) {
                subLog.info("该身份证号+清算卡号已经绑定过");
                return super.getRspMap(RspCodeConstant.RSPCODE_200105, null, null);
            }
            //调用四要素认证接口
            Map<String, String> map = new HashMap<>();
            map.put(SystemConstant.SESSION_LOGIN_USER, login_id);
            Map resultMap = iFourElementService.queryFourElement(new FourElements(customInf.getIns_uuid(), name, credit_phone, certificate_no, credit_card_no), map);
            if (resultMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
                //四要素认证成功
                subLog.info("【{}】四要素认证成功",login_id);
                //修改用户信息
                boolean flag = false;
                String review_st = SystemConstant.REVIEW_ST_8;
                if(SystemConstant.REVIEW_ST_2.equals(customInf.getRealname_audit_st())){
                    //退回修改 改为待审核
                    review_st = SystemConstant.REVIEW_ST_0;
                    flag = true;
                }else if(SystemConstant.REVIEW_ST_0.equals(customInf.getRealname_audit_st())){
                    //待审核进来仍待审核，不发起工作流（什么情况会走这一步： 退回修改，资料界面点下一步，然后从照片界面再回退回资料界面，再此点击下一步）
                    review_st = SystemConstant.REVIEW_ST_0;
                }
                appCustomerInfoService.updateCustomInfoAfterRealNameAuth(custom_no, certificate_no, name,review_st);
                //加载清算卡信息
                App_Custom_BankcardEntity debitCardEntity = customBankcardInfoService.getBankcardEntity(customInf.getCustom_uuid(), SystemConstant.ACCT_ATTR_0);
                if(debitCardEntity == null){ //第一次进行实名认证保存卡信息
                    debitCardEntity = new App_Custom_BankcardEntity();
                }
                //保存清算卡/借记卡信息
                debitCardEntity.setCustom_uuid(customInf.getCustom_uuid());
                debitCardEntity.setSuper_bank_no(super_bank_no);
                debitCardEntity.setSuper_bank_nm(super_bank_nm);
                debitCardEntity.setSettle_bank_no(settle_bank_no);
                debitCardEntity.setSettle_acct(settle_acct);
                debitCardEntity.setAcct_nm(acct_nm);
                debitCardEntity.setBank_nm(bank_nm);
                debitCardEntity.setBank_province(bank_province);
                debitCardEntity.setBank_locality(bank_locality);
                debitCardEntity.setPhone(settle_phone);
                debitCardEntity.setCertificate_no(certificate_no);
                debitCardEntity.setAcct_attr(SystemConstant.ACCT_ATTR_0);
                debitCardEntity.setAudit_st(SystemConstant.REVIEW_ST_0);//未审核
                customBankcardInfoService.saveCustomBankcard(debitCardEntity, map);
                subLog.info("已保存清算卡信息");
                //保存信用卡信息
                App_Custom_BankcardEntity creditCardEntity = customBankcardInfoService.getBankcardEntity(customInf.getCustom_uuid(), SystemConstant.ACCT_ATTR_1);
                if(creditCardEntity == null){
                    creditCardEntity = new App_Custom_BankcardEntity();
                }
                creditCardEntity.setCustom_uuid(customInf.getCustom_uuid());
                creditCardEntity.setSuper_bank_no(StringUtils.objToString(creditCardBinInf.get("super_bank_no")));
                creditCardEntity.setSuper_bank_nm(StringUtils.objToString(creditCardBinInf.get("super_bank_name")));
                // *
                //creditCardEntity.setSettle_bank_no(StringUtils.objToString(creditCardBinInf.get("card_ins_cd")));
                // *
                creditCardEntity.setSettle_acct(credit_card_no);
                // *
                creditCardEntity.setAcct_nm(acct_nm);
                // *
                //creditCardEntity.setBank_nm(StringUtils.objToString(creditCardBinInf.get("card_ins_nm")));
                //creditCardEntity.setBank_province(StringUtils.objToString(creditCardBinInf.get("bank_province")));
                //creditCardEntity.setBank_locality(StringUtils.objToString(creditCardBinInf.get("bank_locality")));
                creditCardEntity.setPhone(credit_phone);
                creditCardEntity.setCvv2(cvv2);
                creditCardEntity.setCrd_exp(crd_exp);
                creditCardEntity.setCertificate_no(certificate_no);
                creditCardEntity.setAcct_attr(SystemConstant.ACCT_ATTR_1);
                creditCardEntity.setAudit_st(SystemConstant.REVIEW_ST_0); //未审核
                creditCardEntity.setAuth_bank_card_st(SystemConstant.AUTH_BANK_CARD_ST_1);
                customBankcardInfoService.saveCustomBankcard(creditCardEntity, map);
                subLog.info("已保存信用卡信息");
                //判断是否要发起工作流：  如果是第一次提交实名认证审核，那么不发起，留待上传图片接口发起；
                //                      如果是退回修改后再次提交的实名认证审核，那么发起工作流，上传图片接口不再发起；
                if(flag){
                    //发起审核工作流
                    App_WorkFlow_TraceEntity workEntity = appWorkflowTraceService.getWorkflowEntity(DBConstant.Table.T_APP_CUSTOM_INF.name(),customInf.getCustom_uuid());
                    //未发起过工作流或者发起的工作流状态是退回修改，那么就新建工作流对象（）
                    if(workEntity == null || SystemConstant.STATE_CHANGE_2.equals(workEntity.getNew_state())){
                        workEntity = new App_WorkFlow_TraceEntity();
                    }
                    workEntity.setLogin_name(login_id);
                    workEntity.setSystem_type(DBConstant.Table.T_APP_CUSTOM_INF.name());
                    workEntity.setSystem_key(customInf.getCustom_uuid());
                    workEntity.setNew_state(SystemConstant.WORKFLOW_NODE_0);
                    workEntity.setState_operate(SystemConstant.STATE_CHANGE_0);
                    appWorkflowTraceService.saveWorkflowTrace(workEntity, map);
                }
                subLog.info("实名认证已完成，接口返回");
                return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, null);
            } else {
                //返回四要素失败认证信息
                subLog.info("四要素认证失败");
                return getRspMap(RspCodeConstant.RSPCODE_300028, StringUtils.objToString(resultMap.get(SystemConstant.RSP_MSG)), null);
            }
        } else {
            return checkSignMap;
        }

    }

    /**
     *银行卡卡号校验
     * @param settle_acct
     * @return
     */
    private static boolean checkNumber(String settle_acct){
        String settleAcctr = String.valueOf(settle_acct);
        if(!settleAcctr.startsWith("62")){
            return false;
        }
        return true;
    }

    /**
     * 变更登陆账号
     *
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param certificate_no
     * @param new_login_id
     * @param pass_word
     * @param rand
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map changeLoginId(HttpServletRequest request, String login_id, String random_number, String custom_no,
                             String certificate_no, String new_login_id, String pass_word, String rand,String change_desc, String sign, GpsEntity gpsEntity)throws  Exception {
        //验签
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(custom_no) + StringUtils.objToString(certificate_no) + StringUtils.objToString(new_login_id) + StringUtils.objToString(pass_word);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/changeLoginId.do", gpsEntity, "变更登陆号接口");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
                subLog.info("登录账户无效:{}");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //登陆号校验
            if(new_login_id.equals(customInf.getLogin_id())){
                return super.getRspMap(RspCodeConstant.RSPCODE_200013, null, null);
            }
            //校验新手机号是否存在
            App_Custom_InfEntity newCustomer = appCustomerInfoService.getCustomInfByLoginId(new_login_id);
            if(newCustomer != null){
                return super.getRspMap(RspCodeConstant.RSPCODE_200013, null, null);
            }
            //密码加密
            String pwdRspCode = appCustomerInfoService.getNewPassWord(pass_word,login_id,customInf.getCustom_no());
            subLog.debug("密码:{}", pwdRspCode);
            //密码校验
            if(!pwdRspCode.equals(customInf.getPass_word())){
                return super.getRspMap(RspCodeConstant.RSPCODE_200023, null, null);
            }
            //校验身份证号
            if(!certificate_no.equals(customInf.getCertificate_no())){
                subLog.info("身份证号不存在:{}",certificate_no);
                return super.getRspMap(RspCodeConstant.RSPCODE_200022, null, null);
            }
            //查询手机变更号
            boolean tempPhone = customLoginidChangeService.getPhone(new_login_id,login_id);
            if(tempPhone){
                return super.getRspMap(RspCodeConstant.RSPCODE_200013, null, null);
            }
            //验证码校验
            boolean tempRand = smsCodeFlowService.checkRand(SystemConstant.RAND_SERVICE_TYPE_5, new_login_id, rand);
            if (!tempRand) {
                return this.getRspMap(RspCodeConstant.RSPCODE_200006, null, null);
            }
            subLog.debug("本地验证码:{}", tempRand);
            //插入变更表数据
            String RspCode = customLoginidChangeService.instChangeLoginId(request, customInf.getCustom_uuid(), login_id, new_login_id,change_desc);
            if (StringUtils.isEmpty(RspCode)) {
                return super.getRspMap(RspCodeConstant.RSPCODE_200020, null, null);
            }
            //插入变更登陆号
            String updChangeLogin = appCustomerInfoService.changeLoginId(request, login_id, custom_no, certificate_no, new_login_id);
            if (StringUtils.isEmpty(updChangeLogin)) {
                return super.getRspMap(RspCodeConstant.RSPCODE_200021, null, null);
            }
            subLog.info("变更成功:{}", updChangeLogin);
        }
        return checkSignMap;
    }

    /**
     * 上传图片
     *
     * @param request
     * @param response
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param pic_count
     * @param sign
     * @param gpsEntity
     * @param custom_pic1
     * @param custom_pic2
     * @param custom_pic3
     * @param custom_pic4
     * @param custom_pic5
     * @return
     */
    public Map saveRealNamePic(HttpServletRequest request, HttpServletResponse response,
                               String login_id, String random_number, String custom_no,
                               String pic_count,String sign, GpsEntity gpsEntity,
                               MultipartFile custom_pic1,MultipartFile custom_pic2,MultipartFile custom_pic3,
                               MultipartFile custom_pic4,MultipartFile custom_pic5,MultipartFile custom_pic6) {
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(custom_no) + StringUtils.objToString(pic_count);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/saveRealNamePic.do", gpsEntity, "上传图片接口");
        subLog.info("实名认证上传图片接口调用");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
                if (StringUtils.isBlank(login_id) || StringUtils.isBlank(custom_no)) {
                    subLog.info("参数信息不全，返回");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
                }
                //根据登录账户得到登录会员信息
                App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
                //未查到对应用户信息
                if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
                    subLog.info("登录账户无效");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
                }
                //设置大小类，分别上传
                //1 身份证正面照
                MposResponse mposResponse = super.uploadImgForApp(request, response, custom_pic1, customInf.getCustom_uuid(),
                        SystemConstant.AFFIX_TP_01, SystemConstant.STORE_TP_01_04, login_id, custom_no);

                if (ExceptionConstant.ERROR.getCode().equals(mposResponse.getRespCode())) {
                    subLog.info("身份证正面照-图片上传异常");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200108, null, null);
                }
                //2 身份证反面照
                mposResponse = super.uploadImgForApp(request, response, custom_pic2, customInf.getCustom_uuid(),
                        SystemConstant.AFFIX_TP_01, SystemConstant.STORE_TP_01_05, login_id, custom_no);
                if (ExceptionConstant.ERROR.getCode().equals(mposResponse.getRespCode())) {
                    subLog.info("身份证反面照-图片上传异常");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200108, null, null);
                }
                //3 银行卡正面照片
                mposResponse = super.uploadImgForApp(request, response, custom_pic3, customInf.getCustom_uuid(),
                        SystemConstant.AFFIX_TP_02, SystemConstant.STORE_TP_02_01, login_id, custom_no);
                if (ExceptionConstant.ERROR.getCode().equals(mposResponse.getRespCode())) {
                    subLog.info("银行卡正面照片-图片上传异常");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200108, null, null);
                }
                //6 银行卡反面照片
                mposResponse = super.uploadImgForApp(request, response, custom_pic6, customInf.getCustom_uuid(),
                        SystemConstant.AFFIX_TP_02, SystemConstant.STORE_TP_02_02, login_id, custom_no);
                if (ExceptionConstant.ERROR.getCode().equals(mposResponse.getRespCode())) {
                    subLog.info("银行卡反面照片-图片上传异常");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200108, null, null);
                }
                //4 手持身份证银行卡
                mposResponse = super.uploadImgForApp(request, response, custom_pic4, customInf.getCustom_uuid(),
                        SystemConstant.AFFIX_TP_02, SystemConstant.STORE_TP_02_03, login_id, custom_no);
                if (ExceptionConstant.ERROR.getCode().equals(mposResponse.getRespCode())) {
                    subLog.info("手持身份证银行卡-图片上传异常");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200108, null, null);
                }
                //5 信用卡正面照
                mposResponse = super.uploadImgForApp(request, response, custom_pic5, customInf.getCustom_uuid(),
                        SystemConstant.AFFIX_TP_01, SystemConstant.STORE_TP_01_06, login_id, custom_no);
                if (ExceptionConstant.ERROR.getCode().equals(mposResponse.getRespCode())) {
                    subLog.info("信用卡正面照-图片上传异常");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200108, null, null);
                }
                subLog.info("图片上传完成，修改用户状态为待审核");
                //判断是否需要发起工作流
                if(SystemConstant.REVIEW_ST_8.equals(customInf.getRealname_audit_st())){
                    //如果审核状态是资料未提交，表示是第一次进行实名认证上传图片，那么发起工作流；
                    //修改审核状态
                    appCustomerInfoService.updateCustomAuditStatus(login_id,custom_no,SystemConstant.REVIEW_ST_0);
                    //发起工作流
                    Map<String, String> map = new HashMap<>();
                    map.put(SystemConstant.SESSION_LOGIN_USER, login_id);
                    //发起审核工作流
                    App_WorkFlow_TraceEntity workEntity = appWorkflowTraceService.getWorkflowEntity(DBConstant.Table.T_APP_CUSTOM_INF.name(),customInf.getCustom_uuid());
                    //未发起过工作流或者发起的工作流状态是退回修改，那么就新建工作流对象（）
                    if(workEntity == null || SystemConstant.STATE_CHANGE_2.equals(workEntity.getNew_state())){
                        workEntity = new App_WorkFlow_TraceEntity();
                    }
                    workEntity.setLogin_name(login_id);
                    workEntity.setSystem_type(DBConstant.Table.T_APP_CUSTOM_INF.name());
                    workEntity.setSystem_key(customInf.getCustom_uuid());
                    workEntity.setNew_state(SystemConstant.WORKFLOW_NODE_0);
                    workEntity.setState_operate(SystemConstant.STATE_CHANGE_0);
                    appWorkflowTraceService.saveWorkflowTrace(workEntity, map);
                }
                subLog.info("上传图片接口已完成，接口返回");
                return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, null);
        }
        return checkSignMap;
    }


    /**
     *  修改密码
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param pass_word
     * @param new_pass_word
     * @param rand
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map changePassWord(HttpServletRequest request, String login_id, String random_number, String custom_no,
                              String pass_word, String new_pass_word, String rand, String sign, GpsEntity gpsEntity) throws  Exception {
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(login_id) + StringUtils.objToString(custom_no) + StringUtils.objToString(pass_word) + StringUtils.objToString(rand)+StringUtils.objToString(new_pass_word);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/changePassWord.do", gpsEntity, "修改密码接口");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
                subLog.info("登录账户无效:{}");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //旧密码加密
            String oldPwdRspCode = appCustomerInfoService.getNewPassWord(pass_word,login_id,customInf.getCustom_no());
            subLog.debug("旧密码:{}", oldPwdRspCode);
            //旧密码校验
            if(!oldPwdRspCode.equals(customInf.getPass_word())){
                return super.getRspMap(RspCodeConstant.RSPCODE_200023, null, null);
            }
            boolean tempRand = smsCodeFlowService.checkRand(SystemConstant.RAND_SERVICE_TYPE_3,login_id,rand);
            subLog.debug("本地验证码:{}", tempRand);
            if(!tempRand){
                return this.getRspMap(RspCodeConstant.RSPCODE_200006,null,null);
            }else {
                smsCodeFlowService.updRand(SystemConstant.RAND_SERVICE_TYPE_3,login_id,rand);
            }
            //新密码加密
            String newPwdRspCode = appCustomerInfoService.getNewPassWord(new_pass_word,login_id,customInf.getCustom_no());
            subLog.debug("新密码:{}", newPwdRspCode);
            //新密码和老密码校验
            if(newPwdRspCode.equals(customInf.getPass_word())){
                return super.getRspMap(RspCodeConstant.RSPCODE_200026, null, null);
            }
            //修改密码
            String updChangePassWord = appCustomerInfoService.changePassWord(request,login_id, custom_no,newPwdRspCode,customInf);
            if (StringUtils.isEmpty(updChangePassWord)) {
                return super.getRspMap(RspCodeConstant.RSPCODE_200021, null, null);
            }
            subLog.info("修改密码成功:{}",updChangePassWord);
        }
        return checkSignMap;
    }

    /**
     * 变更结算卡
     * @param request
     * @param response
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param bankcard_uuid
     * @param super_bank_no
     * @param super_bank_nm
     * @param bank_province
     * @param bank_locality
     * @param settle_bank_no
     * @param bank_nm
     * @param settle_acct
     * @param acct_nm
     * @param pic_count
     * @param custom_pic1
     * @param custom_pic2
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map modifySettleBank(HttpServletRequest request, HttpServletResponse response,
                         String login_id, String random_number, String custom_no,
                         String bankcard_uuid, String super_bank_no, String super_bank_nm,
                         String bank_province, String bank_locality, String settle_bank_no, String bank_nm,String settle_acct,String settle_phone,String acct_nm,
                         String pic_count,  MultipartFile custom_pic1,MultipartFile custom_pic2,MultipartFile custom_pic3,String sign,GpsEntity gpsEntity){
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number())+StringUtils.objToString(custom_no)
                +StringUtils.objToString(bankcard_uuid)+StringUtils.objToString(super_bank_no)+StringUtils.objToString(super_bank_nm)
                +StringUtils.objToString(bank_province)+StringUtils.objToString(bank_locality)+StringUtils.objToString(settle_bank_no)
                +StringUtils.objToString(bank_nm)+StringUtils.objToString(settle_acct)+StringUtils.objToString(acct_nm)+StringUtils.objToString(pic_count);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id,"httpcustom/modifySettleBank.do",gpsEntity,"变更结算卡");
        subLog.info("变更结算卡接口调用");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            //参数非空校验
            if (StringUtils.isBlank(super_bank_no) || StringUtils.isBlank(settle_phone) || StringUtils.isBlank(super_bank_nm) || StringUtils.isBlank(bank_province) || StringUtils.isBlank(bank_locality)
                    || StringUtils.isBlank(settle_bank_no) || StringUtils.isBlank(bank_nm) || StringUtils.isBlank(settle_acct) || StringUtils.isBlank(acct_nm)) {
                subLog.info("参数为空");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            Map<String, String> settleCardBinInf = cardBinDao.getCardBinAttr(settle_acct);
            String setcrd_nature = settleCardBinInf.get("crd_nature");
            if (!SystemConstant.CRD_NATURE_1.equals(setcrd_nature)) {
                subLog.info("不是有效的借记卡");
                return super.getRspMap(RspCodeConstant.RSPCODE_200107, null, null);
            }
            //银行卡校验是否是银联标准卡
            Boolean checkNumber = this.checkNumber(settle_acct);
            if(!checkNumber){
                return super.getRspMap(RspCodeConstant.RSPCODE_200115, null, null);
            }
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if(customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())){
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007,null,null);
            }
            //校验该会员是否已实名认证
            if(SystemConstant.AUTH_ST_0.equals(customInf.getRealname_auth_st())){
                subLog.info("尚未实名认证");
                return super.getRspMap(RspCodeConstant.RSPCODE_200110,null,null);
            }
            //重复性校验
            //再看清算账户是否已经绑定过
            boolean saved = customBankcardInfoService.alreadySaveCardInfo(customInf.getCustom_uuid(),settle_acct);
            if(saved){
                //说明是别人绑过该卡了
                subLog.info("该身份证号+清算卡号已经绑定过");
                return super.getRspMap(RspCodeConstant.RSPCODE_200105, null, null);
            }
            //处理图片不上传问题
            Map<String,Object> map = new HashMap<>();
            map.put(SystemConstant.SESSION_LOGIN_USER,login_id);
            //拷贝记录逻辑： 为了照顾到审核以及回显操作， 如果当前操作没有大类为3的照片，拷贝大类2的记录为3；
            if(custom_pic1 == null){
                //查询31图片，没有则新增记录
                App_Affix_InfEntity entity31 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(), SystemConstant.AFFIX_TP_03, SystemConstant.STORE_TP_03_01);
                if(entity31 == null){
                    App_Affix_InfEntity entity21 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(), SystemConstant.AFFIX_TP_02, SystemConstant.STORE_TP_02_01);
                    //
                    entity21.setAffix_uuid(null);
                    entity21.setAffix_tp(SystemConstant.AFFIX_TP_03);
                    entity21.setStore_tp(SystemConstant.STORE_TP_03_01);
                    appAffixInfService.saveAffixPicForApp(entity21,map);
                }
            }
            if(custom_pic2 == null){
                //查询33图片，没有则新增记录
                App_Affix_InfEntity entity33 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(), SystemConstant.AFFIX_TP_03, SystemConstant.STORE_TP_03_03);
                if(entity33 == null){
                    App_Affix_InfEntity entity23 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(), SystemConstant.AFFIX_TP_02, SystemConstant.STORE_TP_02_03);
                    //
                    entity23.setAffix_uuid(null);
                    entity23.setAffix_tp(SystemConstant.AFFIX_TP_03);
                    entity23.setStore_tp(SystemConstant.STORE_TP_03_03);
                    appAffixInfService.saveAffixPicForApp(entity23,map);
                }
            }
            if(custom_pic3 == null){
                //查询32图片，没有则新增记录
                App_Affix_InfEntity entity32 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(), SystemConstant.AFFIX_TP_03, SystemConstant.STORE_TP_03_02);
                if(entity32 == null){
                    App_Affix_InfEntity entity22 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(), SystemConstant.AFFIX_TP_02, SystemConstant.STORE_TP_02_02);
                    if(entity22 != null){
                        entity22.setAffix_uuid(null);
                        entity22.setAffix_tp(SystemConstant.AFFIX_TP_03);
                        entity22.setStore_tp(SystemConstant.STORE_TP_03_02);
                        appAffixInfService.saveAffixPicForApp(entity22,map);
                    }
                }
            }
            //3 银行卡照片
            MposResponse mposResponse = super.uploadImgForApp(request, response, custom_pic1, customInf.getCustom_uuid(),
                    SystemConstant.AFFIX_TP_03, SystemConstant.STORE_TP_03_01, login_id, custom_no);
            if (ExceptionConstant.ERROR.getCode().equals(mposResponse.getRespCode())) {
                subLog.info("银行卡正面照片-图片上传异常");
                return super.getRspMap(RspCodeConstant.RSPCODE_200108, null, null);
            }
            //6 银行卡反面照片
            mposResponse = super.uploadImgForApp(request, response, custom_pic3, customInf.getCustom_uuid(),
                    SystemConstant.AFFIX_TP_03, SystemConstant.STORE_TP_03_02, login_id, custom_no);
            if (ExceptionConstant.ERROR.getCode().equals(mposResponse.getRespCode())) {
                subLog.info("银行卡反面照片-图片上传异常");
                return super.getRspMap(RspCodeConstant.RSPCODE_200108, null, null);
            }
            //4 手持身份证银行卡
            mposResponse = super.uploadImgForApp(request, response, custom_pic2, customInf.getCustom_uuid(),
                    SystemConstant.AFFIX_TP_03, SystemConstant.STORE_TP_03_03, login_id, custom_no);
            if (ExceptionConstant.ERROR.getCode().equals(mposResponse.getRespCode())) {
                subLog.info("手持身份证银行卡-图片上传异常");
                return super.getRspMap(RspCodeConstant.RSPCODE_200108, null, null);
            }
            //插入 清算卡记录 （0）
            //保存清算卡借记卡信息
            //获取待审核或退回修改的卡信息 //其实只能查退回修改的
            App_Custom_BankcardEntity entity = customBankcardInfoService.getBankcardEntityForChangeCard(customInf.getCustom_uuid(), SystemConstant.ACCT_ATTR_0);
            if(entity == null){ //实名认证后 第一次进行银行卡变更
                entity = new App_Custom_BankcardEntity();
                //记录是从哪张卡变更过来的
                entity.setChange_bankcard_uuid(bankcard_uuid);
            }
            entity.setCustom_uuid(customInf.getCustom_uuid());
            entity.setSuper_bank_no(super_bank_no);
            entity.setSuper_bank_nm(super_bank_nm);
            entity.setSettle_bank_no(settle_bank_no);
            entity.setSettle_acct(settle_acct);
            entity.setAcct_nm(acct_nm);
            entity.setBank_nm(bank_nm);
            entity.setBank_province(bank_province);
            entity.setBank_locality(bank_locality);
            entity.setPhone(settle_phone);
            entity.setCertificate_no(customInf.getCertificate_no());
            entity.setAcct_attr(SystemConstant.ACCT_ATTR_0);
            entity.setAudit_st(SystemConstant.REVIEW_ST_0);//未审核
            String bank_uuid = customBankcardInfoService.saveCustomBankcard(entity,map);
            subLog.info("已保存清算卡信息");
            //发起审核工作流
            App_WorkFlow_TraceEntity workEntity = appWorkflowTraceService.getWorkflowEntity(DBConstant.Table.T_APP_CUSTOM_BANKCARD.name(),bank_uuid);
            //未发起过工作流或者发起的工作流状态是退回修改，那么就新建工作流对象（）
            if(workEntity == null || SystemConstant.STATE_CHANGE_2.equals(workEntity.getNew_state())){
                workEntity = new App_WorkFlow_TraceEntity();
            }
            workEntity.setLogin_name(login_id);
            workEntity.setSystem_type(DBConstant.Table.T_APP_CUSTOM_BANKCARD.name());
            workEntity.setSystem_key(bank_uuid);
            workEntity.setNew_state(SystemConstant.WORKFLOW_NODE_0);
            workEntity.setState_operate(SystemConstant.STATE_CHANGE_0);
            appWorkflowTraceService.saveWorkflowTrace(workEntity,map);
            subLog.info("变更结算卡完成，接口已返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, null);
        }
        return checkSignMap;
    }

    /**
     * 查询分润余额
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map getCustomBalance(HttpServletRequest request, String login_id, String random_number, String custom_no, String sign, GpsEntity gpsEntity) {
       String serviceData = StringUtils.objToString(gpsEntity.getSerial_number())+ StringUtils.objToString(custom_no);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/getCustomBalance.do", gpsEntity, "查询账户余额接口");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //分润余额
            List<Map<String, String>> profitBalancelist = customAccountService.getProfitBalance(customInf.getCustom_uuid());
            String profit = String.valueOf(profitBalancelist.get(0).get("profit"));
            String withdraw_profit = String.valueOf(profitBalancelist.get(0).get("withdraw_profit"));

            //推荐佣金和可提现推荐佣金
            List<Map<String, String>> recmdCommissionlist = customAccountService.getRecmdCommission(customInf.getCustom_uuid());
            String recmd_commission = String.valueOf(recmdCommissionlist.get(0).get("recmd_commission"));
            String recmd_withdraw_commission = String.valueOf(recmdCommissionlist.get(0).get("recmd_withdraw_commission"));

            //充值佣金和可提现充值佣金
            List<Map<String, String>> commissionBalancelist = customAccountService.getCommission(customInf.getCustom_uuid());
            String commission = String.valueOf(commissionBalancelist.get(0).get("commission"));
            String withdraw_commission = String.valueOf(commissionBalancelist.get(0).get("withdraw_commission"));

            //总金额
            String  all_amt = customAccountService.getCustomAccountBalance(customInf.getCustom_uuid());
            //总金额
           /* Double all_amt= MathUtils.add(new Double(profit),new Double(commission));*/
            Map dataMap = new HashMap();
            dataMap.put("profit", profit);
            dataMap.put("commission", commission);
            dataMap.put("recmd_commission", recmd_commission);
            dataMap.put("withdraw_profit", withdraw_profit);
            dataMap.put("withdraw_commission", withdraw_commission);
            dataMap.put("recmd_withdraw_commission", recmd_withdraw_commission);
            dataMap.put("all_amt", all_amt);
            subLog.info("查询账户余额{}", dataMap);
            return this.getRspMap(SystemConstant.RSPCODE_SUCCESS, SystemConstant.RSPCODE_SUCCESS_MSG, dataMap);
        }
        return checkSignMap;
    }

    /**
     * 获取我的推荐用户
     * @param request
     * @param login_id
     * @param custom_no
     * @param random_number
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map getMyRecommendUser(HttpServletRequest request,String login_id,String random_number,String custom_no,String curr_page,String rows_perpage, String sign, GpsEntity gpsEntity){
    	String serviceData = StringUtils.objToString(gpsEntity.getSerial_number())+StringUtils.objToString(custom_no)+StringUtils.objToString(curr_page)+StringUtils.objToString(rows_perpage);
    	Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(),sign,random_number, gpsEntity.getVersion(), serviceData, login_id, "httpcustom/getMyRecommendUser.do", gpsEntity, "查询我的推荐用户");
    	if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
    		if(StringUtils.isBlank(curr_page)||StringUtils.isBlank(rows_perpage)){
    			subLog.info("参数为空");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
    		}
    		List dataList = appCustomerInfoService.getMyRecommendUser(custom_no,curr_page,rows_perpage);
    		Map dataMap = new HashMap<>();
    		if(CollectionUtil.isEmpty(dataList)){
    			List list = new ArrayList<>();
    			dataMap.put("custom_list",list);
    			return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, dataMap);
    		}
    		dataMap.put("custom_list", dataList);
    		subLog.info("获取我的推荐用户{}",dataMap);
    		return this.getRspMap(SystemConstant.RSPCODE_SUCCESS, SystemConstant.RSPCODE_SUCCESS_MSG, dataMap);
    	}
    	return checkSignMap;
    }

    /**
     * 查询我的推荐用户详情
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map getMyRecommendUserDetail(HttpServletRequest request,String login_id,String random_number,String custom_no,String sign,GpsEntity gpsEntity){
    	String serviceData = StringUtils.objToString(gpsEntity.getSerial_number())+StringUtils.objToString(custom_no);
    	Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number, gpsEntity.getVersion(), serviceData, login_id, "httpcustom/getMyRecommendUserDetail.do", gpsEntity, "查询我的推荐用户详情");
    	if(checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)){
    		Map dataMap = new HashMap<>();
    		String count = appCustomerInfoService.getMyRecommendUserNumber(login_id,custom_no);
    		String profit = appCustomerInfoService.getMyRecommendProfit(login_id, custom_no);
    		String commission = appCustomerInfoService.getMyRecommendCommission(login_id, custom_no);
    		if(StringUtils.isBlank(profit)){
    			profit = "0.00";
    		}
    		if(StringUtils.isBlank(commission)){
    			commission = "0.00";
    		}
    		dataMap.put("direct_count_people", count);
    		dataMap.put("contri_profit", profit);
    		dataMap.put("contri_commission", commission);
    		subLog.info("查询我的推荐用户详情{}",dataMap);
    		return this.getRspMap(SystemConstant.RSPCODE_SUCCESS, SystemConstant.RSPCODE_SUCCESS_MSG, dataMap);
    	}
    	return checkSignMap;
    }

    /**
     * 意见反馈
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param sign
     * @param title
     * @param content
     * @param gpsEntity
     * @return
     */
    public Map saveFeedback(HttpServletRequest request,String login_id,String random_number,String custom_no, String sign,String title,String content,GpsEntity gpsEntity){
    	String serviceData = StringUtils.objToString(gpsEntity.getSerial_number())+StringUtils.objToString(custom_no)+StringUtils.objToString(title);
    	Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number, gpsEntity.getVersion(), serviceData, login_id, "httpcustom/saveFeedback.do", gpsEntity, "意见反馈");
    	if(checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)){
    		if(StringUtils.isBlank(custom_no) || StringUtils.isBlank(title) || StringUtils.isBlank(content)){
                subLog.info("参数信息不全，返回");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003,null,null);
            }
    		Map<String, String> map = new HashMap<>();
            map.put(SystemConstant.SESSION_LOGIN_USER, login_id);
    		//新增意见反馈
    		App_Client_FeedBackEntity app_Client_FeedBackEntity = new App_Client_FeedBackEntity();
    		App_Custom_InfEntity app_Custom_InfEntity = appCustomerInfoService.getCustomByNo(custom_no);
    		app_Client_FeedBackEntity.setCustom_uuid(app_Custom_InfEntity != null ?app_Custom_InfEntity.getCustom_uuid():null);
    		Map result = appInsInfService.getAppNameAndInsUuid(gpsEntity);
    		if(result!= null){
    			app_Client_FeedBackEntity.setApp_name(StringUtils.objToString(result.get("app_name_app")));
    			app_Client_FeedBackEntity.setIns_uuid(StringUtils.objToString(result.get("ins_uuid")));
    		}
    		app_Client_FeedBackEntity.setTitle(title);
    		app_Client_FeedBackEntity.setContent(content);
    		app_Client_FeedBackEntity.setApp_type(gpsEntity.getAppType());
    		app_Client_FeedBackEntity.setApp_id(gpsEntity.getApp_id());
    		app_Client_FeedBackEntity.setSystem_name(gpsEntity.getSystem_name());
    		app_Client_FeedBackEntity.setSystem_uuid(gpsEntity.getSystem_uuid());
    		app_Client_FeedBackEntity.setSystem_version(gpsEntity.getSystem_version());
    		app_Client_FeedBackEntity.setSystem_device_model(gpsEntity.getSystem_device_model());
    		app_Client_FeedBackEntity.setClient_version(gpsEntity.getSystem_version());
    		feedbackService.saveFeedBack(app_Client_FeedBackEntity, map);
    		subLog.info("意见反馈已保存");
    		return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, null);
    	}
    	return checkSignMap;
    }

    /**
     * 查询会员审核信息
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map getCustomAuditDesc(HttpServletRequest request,String login_id,String random_number,String custom_no,String sign, GpsEntity gpsEntity){
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number())+StringUtils.objToString(custom_no);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number, gpsEntity.getVersion(),
                serviceData, login_id, "httpcustom/getCustomAuditDesc.do", gpsEntity, "查询会员审核信息");
        subLog.info("查询会员审核信息调用");
        if(checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            if (StringUtils.isBlank(custom_no)) {
                subLog.info("参数信息不全，返回");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            Map dataMap = new HashMap();
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if(customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())){
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007,null,null);
            }
            dataMap.put("name",StringUtils.objToString(customInf.getName()));
            dataMap.put("realname_auth_st",customInf.getRealname_auth_st());
            dataMap.put("realname_audit_st",customInf.getRealname_audit_st());
            String realname_audit_desc = appWorkflowTraceService.getAuditCommentsBySystemkey(customInf.getCustom_uuid());
            dataMap.put("realname_audit_desc",realname_audit_desc);
            subLog.info("查询会员审核信息完成，接口已返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, dataMap);
        }
        return checkSignMap;
    }


    /**
     * 查询会员实名认证信息
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map getCustomRealNameInfo(HttpServletRequest request, String login_id, String random_number, String custom_no, String sign, GpsEntity gpsEntity) {
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number())+StringUtils.objToString(custom_no);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number, gpsEntity.getVersion(),
                serviceData, login_id, "httpcommon/getCustomRealNameInfo.do", gpsEntity, "查询会员实名认证信息接口");
        if(checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)){
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null) {
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //借记卡基本信息
            Map dataMap = customBankcardInfoService.getCustomRealNameInfo(custom_no,customInf.getCustom_uuid());
            //如果会员已实名认证（审核通过），加密卡号身份证号信息
            if(SystemConstant.AUTH_ST_1.equals(customInf.getRealname_auth_st())){
                //隐藏身份证号
                dataMap.put("certificate_no",super.hideData("1",StringUtils.objToString(dataMap.get("certificate_no"))));
                //隐藏银行卡号
                dataMap.put("settle_acct",super.hideData("3",StringUtils.objToString(dataMap.get("settle_acct"))));
                dataMap.put("credit_card_no",super.hideData("3",StringUtils.objToString(dataMap.get("credit_card_no"))));
                //隐藏手机号
                dataMap.put("settle_phone",super.hideData("2",StringUtils.objToString(dataMap.get("settle_phone"))));
                dataMap.put("credit_phone",super.hideData("2",StringUtils.objToString(dataMap.get("credit_phone"))));
            }
            subLog.info("查询会员实名认证信息");
            return this.getRspMap(SystemConstant.RSPCODE_SUCCESS, SystemConstant.RSPCODE_SUCCESS_MSG, dataMap);
        }
		return checkSignMap;
    }

    /**
     * 查询会员实名认证图片
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map getCustomRealNamePic(HttpServletRequest request,String login_id,String random_number,String custom_no,String sign, GpsEntity gpsEntity){
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number())+StringUtils.objToString(custom_no);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number, gpsEntity.getVersion(),
                serviceData, login_id, "httpcustom/getCustomRealNamePic.do", gpsEntity, "查询会员实名认证图片");
        subLog.info("查询会员实名认证图片接口调用");
        if(checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            if (StringUtils.isBlank(custom_no)) {
                subLog.info("参数信息不全，返回");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            Map dataMap = new HashMap();
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //根据大小类及是否有变更信息加载图片地址
            //1 身份证正面照
            App_Affix_InfEntity entity14 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(),SystemConstant.AFFIX_TP_01, SystemConstant.STORE_TP_01_04);
            if(entity14 != null){
                dataMap.put("custom_pic1",entity14.getAffix_path());
            }else{
                dataMap.put("custom_pic1","");
            }
            //2 身份证反面照
            App_Affix_InfEntity entity15 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(),SystemConstant.AFFIX_TP_01, SystemConstant.STORE_TP_01_05);
            if(entity15 != null){
                dataMap.put("custom_pic2",entity15.getAffix_path());
            }else{
                dataMap.put("custom_pic2","");
            }
            //银行卡正面照
            App_Affix_InfEntity entity21 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(),SystemConstant.AFFIX_TP_02, SystemConstant.STORE_TP_02_01);
            if(entity21 != null){
                dataMap.put("custom_pic3",entity21.getAffix_path());
            }else{
                dataMap.put("custom_pic3","");
            }
            //银行卡反面
            App_Affix_InfEntity entity22 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(),SystemConstant.AFFIX_TP_02, SystemConstant.STORE_TP_02_02);
            if(entity22 != null){
                dataMap.put("custom_pic6",entity22.getAffix_path());
            }else{
                dataMap.put("custom_pic6","");
            }
            //手持身份证银行卡
            App_Affix_InfEntity entity23 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(),SystemConstant.AFFIX_TP_02, SystemConstant.STORE_TP_02_03);
            if(entity23 != null){
                dataMap.put("custom_pic4",entity23.getAffix_path());
            }else{
                dataMap.put("custom_pic4","");
            }
            //5 信用卡正面照
            App_Affix_InfEntity entity16 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(),SystemConstant.AFFIX_TP_01, SystemConstant.STORE_TP_01_06);
            if(entity16 != null){
                dataMap.put("custom_pic5",entity16.getAffix_path());
            }else{
                dataMap.put("custom_pic5","");
            }
            subLog.info("查询会员实名认证图片完成，接口已返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, dataMap);
        }
        return checkSignMap;
    }

    /**
     * 查询变更结算卡详细信息
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param bankcard_uuid
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map getModifySettleBank(HttpServletRequest request,String login_id,String random_number,
                                   String custom_no,String bankcard_uuid,String sign, GpsEntity gpsEntity){

        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(custom_no) + StringUtils.objToString(bankcard_uuid);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/getModifySettleBank.do", gpsEntity, "查询变更结算卡详细信息");
        subLog.info("查询变更结算卡详细信息接口调用");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            if (StringUtils.isBlank(login_id) || StringUtils.isBlank(custom_no) || StringUtils.isBlank(bankcard_uuid)) {
                subLog.info("参数信息不全，返回");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //借记卡基本信息
            Map dataMap = customBankcardInfoService.getModifySettleBank(bankcard_uuid);
            if(dataMap == null || dataMap.size() == 0){
                subLog.info("参数无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200001, null, null);
            }
            //审核信息
            String audit_desc = appWorkflowTraceService.getAuditCommentsBySystemkey(bankcard_uuid);
            dataMap.put("audit_desc",audit_desc);
            //附件大类
            String affix_tp = SystemConstant.AFFIX_TP_03;
            //3 银行卡照片
            if(StringUtils.compare(SystemConstant.REVIEW_ST_1,StringUtils.objToString(dataMap.get("audit_st")))){
                //审核通过的 取大类为2的图片
                affix_tp = SystemConstant.AFFIX_TP_02;
            }
            App_Affix_InfEntity entity31 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(),affix_tp, SystemConstant.STORE_TP_03_01);
            if(entity31 != null){
                dataMap.put("custom_pic1_path",entity31.getAffix_path());
            }
            App_Affix_InfEntity entity32 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(),affix_tp, SystemConstant.STORE_TP_03_02);
            if(entity32 != null){
                //反面照片
                dataMap.put("custom_pic3_path",entity32.getAffix_path());
            }
            //4 手持身份证银行卡
            App_Affix_InfEntity entity33 = appAffixInfService.getAffixInfByParam(customInf.getCustom_uuid(),affix_tp, SystemConstant.STORE_TP_03_03);
            if(entity33 != null){
                dataMap.put("custom_pic2_path",entity33.getAffix_path());
            }
            dataMap.put("pic_count",3);
            subLog.info("查询变更结算卡详细信息完成，接口已返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, dataMap);
        }
        return checkSignMap;
    }
    /**
     * 分享注册
     * @param request
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map queryShareCustomParam(HttpServletRequest request, String sign, GpsEntity gpsEntity,
                                String login_id, String pass_word, String rand,
                                App_Custom_InfEntity appCustomInfEntity, String pay_pass_word,String sup_custom_uuid) throws Exception {
             Map rspMap = new HashMap();
             boolean tempRand = smsCodeFlowService.checkRand(SystemConstant.RAND_SERVICE_TYPE_1, login_id,rand);
             subLog.debug("本地验证码:{}", tempRand);
            //校验登陆账号是否存在
            App_Custom_InfEntity customInfo = appCustomerInfoService.getCustomInfByLoginId(login_id);
            if (customInfo != null) {
                return this.getRspMap(RspCodeConstant.RSPCODE_200013, null, null);
            }
            //判断验证码是否重复
        /*    if(!rand.equals(tempRand)){
               return this.getRspMap(RspCodeConstant.RSPCODE_200006,null,null);
            }*/
            //查询推荐人
            customInfo = appCustomerInfoService.getCustomByCustomUUID(sup_custom_uuid);
            if (customInfo == null) {
                rspMap.put("dataMap","1");
                return rspMap;
            }
            //判断机构号的uuid
            if (StringUtils.isBlank(customInfo.getIns_uuid())) {
                rspMap.put("dataMap","2");
                return rspMap;
            }
            //注册(分享)
            String cuntomRspCode = appCustomerInfoService.addShareCustomer(login_id, pass_word, pay_pass_word, sup_custom_uuid, customInfo.getIns_uuid());
            Map dataMap = new HashMap();
            dataMap.put("cur_date", DateUtil.getCurrDateTimeStr());
            dataMap.put("cuntomRspCode", cuntomRspCode);
            return httpCommonService.getRspMap(SystemConstant.RSPCODE_SUCCESS, SystemConstant.RSPCODE_SUCCESS_MSG, dataMap);
    }
    /**
     * 用户账号重复性验证
     *
     * @param request
     * @param gpsEntity
     * @param login_id
     * @return
     */
    public Boolean  getLoginId(HttpServletRequest request,HttpServletResponse response , String login_id, String sign, GpsEntity gpsEntity) {
        //获取账号
    	App_Custom_InfEntity customInfo = appCustomerInfoService.getCustomInfByLoginId(login_id);
        if(customInfo == null){
            return true;
        }
        //1是已经存在
        return false;
    }

    /**
     * 获取推荐人手机号
     * @param custom_uuid
     * @return
     */
    public String getSupLoginById(String custom_uuid) {
        //根据登录账户得到登录会员信息
        App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByCustomUUID(custom_uuid);
        //未查到对应用户信息
        if (customInf == null || StringUtils.isBlank(customInf.getCustom_uuid())) {
            subLog.info("登录账户无效");
            return "";
        }
        if(StringUtils.isEmpty(customInf.getLogin_id())){
            return "";
        }
        String supLoginIdTemp = customInf.getLogin_id();
        //加密手机号
        String supLoginId = supLoginIdTemp.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
        return supLoginId;
    }
    /**
     *验证码重复校验
     * @param request
     * @param login_id
     * @return
     */
    public boolean ifExistRand(HttpServletRequest request,HttpServletResponse response , String login_id,String service_type) {
        //判断30秒以该手机号是否发送过验证码
        boolean getRand = smsCodeFlowService.ifExistRand(service_type, login_id);
        if(getRand == false){
            return false;
        }
        return true;
    }
    /**
     *验证码正确与否校验
     * @param request
     * @param login_id
     * @return
     */
    public boolean getCheckRand(HttpServletRequest request,HttpServletResponse response , String login_id,String service_type,String rand) {
        boolean tempRand = smsCodeFlowService.checkRand(SystemConstant.RAND_SERVICE_TYPE_1, login_id, rand);
        subLog.debug("本地验证码:{}", tempRand);
        if (!tempRand) {
            return false;
        }
        return true;
    }

    /**
     * 忘记和修改支付密码
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param pass_word
     * @param old_pay_pass_word
     * @param new_pay_pass_word
     * @param rand
     * @param certificate_no
     * @param change_type 1-修改支付密码 2-忘记支付密码
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map changePayPassWord(HttpServletRequest request,String login_id,String random_number,String custom_no,
                                 String pass_word,String old_pay_pass_word,String new_pay_pass_word,String rand,
                                 String certificate_no,String change_type,String sign, GpsEntity gpsEntity){
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(custom_no) + StringUtils.objToString(pass_word)
                            +StringUtils.objToString(new_pay_pass_word)+StringUtils.objToString(rand)+StringUtils.objToString(change_type);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/changePayPassWord.do", gpsEntity, "忘记和修改支付密码");
        subLog.info("忘记和修改支付密码接口调用");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            //参数非空校验 有效性校验
            if(StringUtils.isBlank(change_type) || ("1".equals(change_type) && StringUtils.isBlank(old_pay_pass_word))
                    || ("2".equals(change_type) && StringUtils.isBlank(certificate_no)) || StringUtils.isBlank(custom_no) || StringUtils.isBlank(login_id)
                    || StringUtils.isBlank(pass_word) || StringUtils.isBlank(new_pay_pass_word)|| StringUtils.isBlank(rand)){
                subLog.info("参数信息不全，返回");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            //根据登录账户得到登录会员信息
            App_Custom_InfEntity customInf = appCustomerInfoService.getCustomByNo(custom_no);
            //未查到对应用户信息
            if (customInf == null) {
                subLog.info("登录账户无效");
                return super.getRspMap(RspCodeConstant.RSPCODE_200007, null, null);
            }
            //登录密码校验
            String newPassWord = null;
            try {
                newPassWord = appCustomerInfoService.getNewPassWord(pass_word, login_id, customInf.getCustom_no());
            } catch (Exception e) {
                e.printStackTrace();
                super.subLog.error("RSA解密异常");
                return super.getRspMap(RspCodeConstant.RSPCODE_200102, null, null);
            }
            //数据库中的密码
            String db_password = customInf.getPass_word();
            if (StringUtils.isEmpty(newPassWord) || StringUtils.isEmpty(db_password)
                    || !StringUtils.compare(newPassWord, db_password)) {
                subLog.info("忘记和修改支付密码失败： 登录密码不正确");
                return super.getRspMap(RspCodeConstant.RSPCODE_200011, "登录密码不正确", null);
            }
            //根据业务类型得到验证码业务类型
            String rand_type = "";
            //分类型进行业务校验
            if("1".equals(change_type)){ //1-修改支付密码
                rand_type = SystemConstant.RAND_SERVICE_TYPE_6;
                //原密码校验
                String oldPayPassWord = null;
                try {
                    oldPayPassWord = appCustomerInfoService.getNewPassWord(old_pay_pass_word, login_id, customInf.getCustom_no());
                } catch (Exception e) {
                    e.printStackTrace();
                    super.subLog.error("RSA解密异常");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200102, null, null);
                }
                //数据库中的密码
                String db_pay_password = customInf.getPay_pass_word();
                if (StringUtils.isEmpty(oldPayPassWord) || StringUtils.isEmpty(db_pay_password)
                        || !StringUtils.compare(oldPayPassWord, db_pay_password)) {
                    subLog.info("修改支付密码操作失败： 原支付密码不正确");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200011, "原支付密码不正确", null);
                }
            }else if("2".equals(change_type)){//2-忘记支付密码
                rand_type = SystemConstant.RAND_SERVICE_TYPE_7;
                //身份证号校验
                if(!StringUtils.compare(certificate_no,customInf.getCertificate_no())){
                    subLog.info("忘记支付密码操作失败：身份证号不正确");
                    return super.getRspMap(RspCodeConstant.RSPCODE_200022, null, null);
                }
            }
            //验证码校验
            boolean tempRand = smsCodeFlowService.checkRand(rand_type, login_id, rand);
            if(!tempRand){
                subLog.info("修改支付密码操作失败： 验证码错误");
                return this.getRspMap(RspCodeConstant.RSPCODE_200006,null,null);
            }else {
                //修改该验证码为无效
                smsCodeFlowService.updRand(rand_type,login_id,rand);
            }
            //保存新的支付密码
            String newPayPassWord = null;
            try {
                newPayPassWord = appCustomerInfoService.getNewPassWord(new_pay_pass_word, login_id, customInf.getCustom_no());
            } catch (Exception e) {
                e.printStackTrace();
                super.subLog.error("RSA解密异常");
                return super.getRspMap(RspCodeConstant.RSPCODE_200102, null, null);
            }
            appCustomerInfoService.updatePayPassword(customInf.getCustom_uuid(),newPayPassWord);
            subLog.info("忘记和修改支付密码接口调用完成，接口已返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, null);
        }
        return checkSignMap;
    }

    /**
     * 查询银行卡详细信息
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param bankcard_uuid
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map getCustomBankCardDetail(HttpServletRequest request,String login_id,String random_number,String custom_no,
                                       String bankcard_uuid,String sign, GpsEntity gpsEntity){
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(custom_no) + StringUtils.objToString(bankcard_uuid);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/getCustomBankCardDetail.do", gpsEntity, "查询银行卡详细信息");
        subLog.info("查询银行卡详细信息接口调用");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            if(StringUtils.isBlank(bankcard_uuid)){
                subLog.info("参数信息不全，返回");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            Map dataMap = customBankcardInfoService.getBankcardInfoByUUID(bankcard_uuid);
            if(dataMap != null && dataMap.get("credit_card_no") != null){
                //隐藏卡号
                dataMap.put("credit_card_no",super.hideData("3",StringUtils.objToString(dataMap.get("credit_card_no"))));
            }
            subLog.info("查询银行卡详细信息完成，接口已返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, dataMap);
        }
        return checkSignMap;
    }

    /**
     * 修改银行卡(信用卡)
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param bankcard_uuid
     * @param cvv2
     * @param crd_exp
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map updateCustomBankCard(HttpServletRequest request,String login_id,String random_number,String custom_no,
                                       String bankcard_uuid,String cvv2,String crd_exp,String sign, GpsEntity gpsEntity){
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(custom_no) + StringUtils.objToString(bankcard_uuid)
                                +StringUtils.objToString(cvv2) + StringUtils.objToString(crd_exp);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/updateCustomBankCard.do", gpsEntity, "修改银行卡");
        subLog.info("修改信用卡接口调用");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            if(StringUtils.isBlank(bankcard_uuid) || StringUtils.isBlank(cvv2) || StringUtils.isBlank(crd_exp)){
                subLog.info("参数信息不全，返回");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            //修改信用卡信息
            customBankcardInfoService.updateCustomBankCard(bankcard_uuid,cvv2,crd_exp);
            subLog.info("修改信用卡信息完成，接口已返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, null);
        }
        return checkSignMap;
    }

    /**
     * 解绑银行卡
     * @param request
     * @param login_id
     * @param random_number
     * @param custom_no
     * @param bankcard_uuid
     * @param sign
     * @param gpsEntity
     * @return
     */
    public Map unbindCustomBankCard(HttpServletRequest request,String login_id,String random_number,String custom_no,
                                       String bankcard_uuid,String sign, GpsEntity gpsEntity){
        String serviceData = StringUtils.objToString(gpsEntity.getSerial_number()) + StringUtils.objToString(custom_no) + StringUtils.objToString(bankcard_uuid);
        Map checkSignMap = this.getLogClientKeyEntity(request, gpsEntity.getSerial_number(), sign, random_number,
                gpsEntity.getVersion(), serviceData, login_id, "httpcustom/unbindCustomBankCard.do", gpsEntity, "解绑银行卡");
        subLog.info("解绑银行卡接口调用");
        if (checkSignMap.get(SystemConstant.RSP_CODE).equals(SystemConstant.RSPCODE_SUCCESS)) {
            if(StringUtils.isBlank(bankcard_uuid)){
                subLog.info("参数信息不全，返回");
                return super.getRspMap(RspCodeConstant.RSPCODE_200003, null, null);
            }
            Map dataMap = customBankcardInfoService.getBankcardInfoByUUID(bankcard_uuid);
            if(dataMap == null){
                //银行卡不存在
                return super.getRspMap(RspCodeConstant.RSPCODE_200014, null, null);
            }
            if(SystemConstant.AUTH_BANK_CARD_ST_1.equals(StringUtils.objToString(dataMap.get("auth_bank_card_st")))){
                //实名认证信用卡无法解绑
                return super.getRspMap(RspCodeConstant.RSPCODE_200112, null, null);
            }
            customBankcardInfoService.unbindCustomBankCard(bankcard_uuid);
            subLog.info("解绑银行卡完成，接口已返回");
            return super.getRspMap(SystemConstant.RSPCODE_SUCCESS, null, null);
        }
        return checkSignMap;
    }


    /**
     * 下载
     * @param sup_custom_uuid
     * @return
     */
    public String httpDownload(String sup_custom_uuid) {

        //获取当前会员的机构号
        App_Custom_InfEntity appCustomInfEntity = appCustomerInfoService.getCustomByCustomUUID(sup_custom_uuid);
        if(appCustomInfEntity.getIns_uuid() == null){
            return null;
        }
        //获取机构唯一主键
        Map appInsUuid = organizationService.getAppInsUuid(appCustomInfEntity.getIns_uuid());
        String getRegUrl = String.valueOf(appInsUuid.get("Android_Update_Url"));
        if(!StringUtils.isEmpty(appInsUuid)){
            //获取更新历史的唯一主键
          String historyUuid = historyService.getHistoryAppUuuid(String.valueOf(appInsUuid.get("INS_APP_UUID")));

          if(StringUtils.isEmpty(historyUuid)){
              return getRegUrl+"upload/appPackage/android/1002501/JQianBao_1002501_1.0.1.apk";
          }
            String newAppUrl = appAffixInfService.getNewAppUrl(historyUuid);
            if(StringUtils.isEmpty(newAppUrl)){
                return getRegUrl+"upload/appPackage/android/1002501/JQianBao_1002501_1.0.1.apk";
            }
            return getRegUrl+String.valueOf(newAppUrl);
        }
       return getRegUrl+"upload/appPackage/android/1002501/JQianBao_1002501_1.0.1.apk";
    }
}
